/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package deatax.network;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;

/**
 *
 * @author Pieman
 */
public class ClientThread extends Thread {

    Client c;
    Socket s;
    PrintWriter output;
    BufferedReader input;

    public ClientThread(Client c, Socket s, BufferedReader input, PrintWriter output) {
        this.c = c;
        this.s = s;
        this.output = output;
        this.input = input;
    }
    
        @Override
        public void run() {
            String line;
            try {
                while ((line = input.readLine()) != null) {
                    System.out.println("got line: " + line);
                    String[] a = line.split("\\|");
                    int type = Integer.parseInt(a[0]);
                    String[] arg;
                    if (a.length > 1) {
                        arg = a[1].split(":");
                    } else {
                        arg = new String[]{};
                    }
                    c.processListeners(type, arg);
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            try {
                input.close();
                output.close();
                s.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }
